<template>
	<view>
		<u-row customStyle="margin-bottom: 80px">
			<u-col span="12">
				<view>
					<u-navbar
					    title="个人简历"
						titleStyle="font-weight:bold"
					    :safeAreaInsetTop="true"
						:fixed='true'
						bgColor="#FFBE59"
						@leftClick="leftClick"
					>
					    <view
					        class="u-nav-slot"
					        slot="left"
							
					    >
					        <u-icon
					            name="arrow-left"
					            size="20"
								color="black"
					        ></u-icon>
					    </view>
					</u-navbar>
				</view>
			</u-col>
		</u-row>
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="12" style="margin: 0 auto;">
				<view class="resume bg-purple-light" style="width: 90%;margin: 0 auto; ">
					<u-col span="12">
						<view class="full-name bg-purple-light" @click="alertDisabled()">
							<p>姓名</p>
						<u--input
						    placeholder="请输入姓名"
						    border="bottom"
						    clearable
							:disabled="true"
							disabledColor="white"
							v-model="fullNameValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="name-title bg-purple-light" @click="showSex=true">
							<span>性别</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p>{{this.sexValue}}</p>
							<u-picker :show="showSex" @confirm="sexConfirm" @cancel="sexCancel" :columns="showSexColumns"></u-picker>
						</view>
					</u-col>
					<u-col span="12">
						<view class="name-title bg-purple-light" @click="showDateTime=true">
							<span>出生年月</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p><uni-dateformat :date="this.dateOfBirthValue" format='yyyy/MM/dd'></uni-dateformat></p>
							<u-datetime-picker
								:show="showDateTime"
								v-model="dateOfBirthValue"
								mode="date"
								:minDate="1980"
								@confirm="dateOfBirthConfirm" 
								@cancel="dateOfBirthCancel"
							></u-datetime-picker>
						</view>
					</u-col>
					<u-col span="12">
						<view class="full-name bg-purple-light">
							<p>户籍所在地</p>
						<u--input
						    placeholder="例: ××省××市××县(区)"
						    border="bottom"
						    clearable
							v-model="registeredResidenceValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="full-name bg-purple-light">
							<p>现居住地</p>
						<u--input
						    placeholder="例: ××省××市××县(区)"
						    border="bottom"
						    clearable
							v-model="currentResidenceValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="name-title bg-purple-light" @click="showIdentity=true">
							<span>当前身份</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
							<p>{{this.identityValue}}</p>
							<u-picker :show="showIdentity" @confirm="identityConfirm" @cancel="identityCancel" :columns="showIdentityColumns"></u-picker>
						</view>
					</u-col>
					
					<u-col span="12">
						<view class="phone bg-purple-light">
							<p>联系方式</p>
						  <u--input
						    placeholder="请输入您的手机号码"
						    border="bottom"
						    v-model="phoneValue"
							type="number"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="email bg-purple-light">
							<p>电子邮箱</p>
						  <u--input
						    placeholder="请输入您的邮箱"
						    border="bottom"
						    v-model="emailValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="keep-button bg-purple-light">
							<u-button type="primary" @click="subPersonal()" text="保存"></u-button>
						</view>
					</u-col>
				</view>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			showSex: false,
							showSexColumns: [
								['男', '女']
							],
							showDateTime: false,
							dateOfBirthValue: "",
							showIdentity: false,
							showIdentityColumns: [
								['职场人', '学生']
							],
							fullNameValue:'',
							sexValue:'',
							registeredResidenceValue:'',
							currentResidenceValue:'',
							phoneValue: '',
							emailValue:'',
							areaProvinceList:[],
							identityValue:'',
							cityList:[],
							resumeList:{},
							stu:{},
							a:'',
						}
					},
					created(){
						//缓存中取出当前登录学生
						this.stu = uni.getStorageSync('stu');
						//学生名称
						this.fullNameValue = this.stu.stuName;
						//根据学生id查询简历
						this.$axios.get('/resume/employmentResume/showStuById?stuId='+this.stu.stuId).then((res)=>{
							if(res.data.success){
								this.a = 1;//用于判断是新增还是修改 1:修改 2:新增
								this.resumeList = res.data.result;
								//编辑回显
								//性别
								let sexArr = ['','男','女'];
								this.sexValue = sexArr[this.resumeList.employmentResumeSex];
								//出生年月
								this.dateOfBirthValue = this.resumeList.employmentResumeBirthday;
								//户籍所在地
								this.registeredResidenceValue = this.resumeList.currentResidence;
								//现居住地
								this.currentResidenceValue = this.resumeList.newCity;
								//当前身份: 职场人/学生
								let identityArr = ['职场人','学生'];
								this.identityValue = identityArr[this.resumeList.employmentResumeIdentity];
								//联系方式
								this.phoneValue = this.resumeList.tel;
								//电子邮箱
								this.emailValue = this.resumeList.mailbox;
							}else{
								this.a = 2;//新增
							}
						});
					},
					methods: {
						//左侧点击返回上一页面
						leftClick(){
							uni.reLaunch({
								url: '/pages/service/practicaltrainingservice/resume/resume',
							});
						},
						//保存
						subPersonal(){
							let flag = true;
							if(this.fullNameValue==undefined||this.fullNameValue==""){
								flag=false;
							}
							if(this.sexValue==undefined||this.sexValue==""){
								flag=false;
							}
							if(this.dateOfBirthValue==undefined||this.dateOfBirthValue==""){
								flag=false;
							}
							if(this.registeredResidenceValue==undefined||this.registeredResidenceValue==""){
								flag=false;
							}
							if(this.currentResidenceValue==undefined||this.currentResidenceValue==""){
								flag=false;
							}
							if(this.identityValue==undefined||this.identityValue==""){
								flag=false;
							}
							if(this.phoneValue==undefined||this.phoneValue==""){
								flag=false;
							}
							if(this.emailValue==undefined||this.emailValue==""){
								flag=false;
							}
							if(flag==true){
								//验证手机号
								let reg =  /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
								if(!reg.test(this.phoneValue)){
									uni.showToast({
										icon: 'error',
										position: 'bottom',
										title: '请填写正确的手机号'
									});
									window.eval(flag);
									return;
								};
								//验证邮箱
								let emailChecking = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
								if(!emailChecking.test(this.emailValue)){
									uni.showToast({
										icon: 'error',
										position: 'bottom',
										title: '请填写正确的邮箱'
									});
									window.eval(flag);
									return;
								};
								//性别
								if(this.sexValue=="男"){
									this.resumeList.employmentResumeSex = 1;
								}else if(this.sexValue=="女"){
									this.resumeList.employmentResumeSex = 2;
								};
								//出生年与
								this.resumeList.employmentResumeBirthday = this.dateOfBirthValue;
								//户籍所在地
								this.resumeList.currentResidence = this.registeredResidenceValue;
								//现居住地
								this.resumeList.newCity = this.currentResidenceValue;
								//当前身份
								if(this.identityValue=="职场人"){
									this.resumeList.employmentResumeIdentity = 0;
								}else if(this.identityValue=="学生"){
									this.resumeList.employmentResumeIdentity = 1;
								};
								//联系方式
								this.resumeList.tel = this.phoneValue;
								//电子邮箱
								this.resumeList.mailbox = this.emailValue;
								if(this.a==1){//修改
									//修改简历个人信息
									this.$axios.post('/resume/employmentResume/upResumeById',this.resumeList).then((res)=>{
										if(res.data.success){
											uni.reLaunch({
												url: '/pages/service/practicaltrainingservice/resume/resume',
											});
										}else{
											uni.showToast({
												icon: 'error',
												position: 'bottom',
												title: '修改失败'
											});
										}
									});
								}else if(this.a==2){//新增
									this.resumeList.stuId = this.stu.stuId;
									this.$axios.post('/resume/employmentResume/addResume',this.resumeList).then((res)=>{
										if(res.data.success){
											uni.reLaunch({
												url: '/pages/service/practicaltrainingservice/resume/resume',
											});
										}else{
											uni.showToast({
												icon: 'error',
												position: 'bottom',
												title: '添加失败'
											});
										}
									});
								}
							}else{
								uni.showToast({
									icon: 'error',
									position: 'bottom',
									title: '信息填写不完整'
								});
							}
						},
						alertDisabled(){
							uni.showToast({
								icon: 'error',
								position: 'bottom',
								title: '姓名不可更改'
							});
							return;
						},
						//回调参数为包含columnIndex、value、values
						sexCancel(){
							this.showSex = false;
						},
						sexConfirm(e) {
							this.sexValue = e.value[0];
							console.log('confirm', e);
							this.showSex = false;
						},
						dateOfBirthCancel(){
							this.showDateTime = false;
						},
						dateOfBirthConfirm(e) {
							console.log('confirm', e)
							this.showDateTime = false;
						},
						identityCancel(){
							this.showIdentity = false;
						},
						identityConfirm(e) {
							this.identityValue = e.value[0];
							console.log('confirm', e);
							this.showIdentity = false;
						},
						areaConfirm(e) {
							console.log('confirm', e);
							this.areaShow = false;
						},
						areaCancel(){
							this.areaShow = false;
						},
						currentResidenceConfirm(e) {
							console.log('confirm', e);
							this.currentResidenceShow = false;
						},
						currentResidenceCancel(){
							this.currentResidenceShow = false;
						},
					}
				}
			</script>

<style lang="less">
	.full-name p,.name-title span,.phone p,.email p{font-size: 14px;color: #3C3C3C;}
		.name-title,.full-name,.phone,.email{margin-top: 20px;height: 56px;}
		.name-title{border-bottom: 0.1px solid #E5E4E2;}
		.name-title p{margin-top: 12px;margin-left:2px;font-size: 14px;font-weight: bold;}
		.name-title-icon{float: right;margin-top: 10px;}
		.keep-button{margin-top: 20px;}
	</style>
</style>
